package com.fdd.service.impl;

import com.fdd.dao.BookDao;
import com.fdd.dao.UserDao;
import com.fdd.service.BookService;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

import java.util.*;

public class BookServiceImpl implements BookService, InitializingBean, DisposableBean {
    private int[] array;
    private List<String> list;
    private Set<String> set;
    private Map<String, String> map;
    private Properties properties;

    private UserDao userDao;
    private BookDao bookDao;

    public void setArray(int[] array) {
        this.array = array;
    }

    public void setList(List<String> list) {
        this.list = list;
    }

    public void setSet(Set<String> set) {
        this.set = set;
    }

    public void setMap(Map<String, String> map) {
        this.map = map;
    }

    public void setProperties(Properties properties) {
        this.properties = properties;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    // 当自动注入byName时，成员变量的名字要和bean id保持一致，所以我们这里要命名为bookDao1，因为在xml中我们是这个id。
    // 注意setter方法的形参不受名字限制。
    public void setBookDao(BookDao abc) {
        this.bookDao = abc;
    }


    public BookServiceImpl() {
        System.out.println("BookServiceImpl::BookServiceImpl()");
    }

    @Override
    public void save() {
        System.out.println("BookServiceImpl::save()");
        bookDao.save();
        userDao.save();

        System.out.println("遍历数组：" + Arrays.toString(array));
        System.out.println("遍历List:" + list);
        System.out.println("遍历Set:" + set);
        System.out.println("遍历Map:" + map);
        System.out.println("遍历Properties" + properties);
    }

    @Override
    public void destroy() {
        System.out.println("Destroy ...");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("init ...");
    }
}
